package cz.af.portletExams.backend.rest;

import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Feed;
import cz.af.portletExams.model.Subject;

import java.util.ArrayList;
import java.util.List;

public class SimpleModelConverter {

    public static List<String> convertToExamsId(Feed feed) {
        final List<String> exams = new ArrayList<String>();
        final List<Entry> entries = feed.getEntries();
        for (Entry entry : entries) {
            final String id = entry.getId();
            final String[] split = id.split(":");
            exams.add(split[split.length - 1]);
        }
        return exams;
    }

    public static List<Subject> convertToSubjects(String string) {
        final List<Subject> subjects = new ArrayList<Subject>();
        final String[] split = string.split(",");
        for (String s : split) {
            final Subject subject = new Subject(s);
            subjects.add(subject);
        }
        return subjects;
    }
}
